import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== antd
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		formData: [
			{ label: '标本条码',			name: 'spec_code',  	half:true, required:true, disabled:true },
			{ label: '加减项类型',		name: 'item_type',  	half:true, required:true, type:'select' },
			{ label: '姓名',			name: 'patient_name',  	half:true, required:true,  },
			{ label: '性别',			name: 'sex',  			half:true, type:'select',idStr:'code' },
			{ label: '项目',			name: 'kind_id',  		half:true, required:true, type:'select',
				onValue: ({value})=> {
					$http.submit(null,'sp-customer-log/kindId',{ param:{ kind_id:value}}).then(data=>{
						this.formRef.setValue({project_name:data[0].major_group_id})
					})
				}
			},
			{ label: '时间',			name: 'op_time',  		half:true,  type:'date-time', format:1 },
			{ label: '岗位',			name: 'project_name',  	half:true, type:'select' },
			{ label: '备注说明',			name: 'remark',  		full:true, type:'textarea' },
			{ label: '图片',			name: 'item_type',  	half:true, type:'upload', multiple:true },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getModalSelect()
	}
	
	onSubmit = () => this.formRef.submit()
	clear = () => this.formRef.reset()
	setValue = ({spec_code, patient_name, sex}) => {
		this.spec_code = spec_code
		this.clear()
		this.formRef.setValue({spec_code, patient_name, sex})
	}
	
	// 获取弹窗下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, ['item_type', 'kind_id','project_name','sex'], ()=>{
			$cache.then( async f => {
				// 加减项类型
				$fn.setRow(formData, 'item_type', await f.add_subtract)
				// 岗位
				$fn.setRow( formData, 'project_name', await f.getCache({ api:'gang_wei' }) )
				// 项目
				$fn.setRow(formData, 'kind_id', await f.getCache({ api:'nature_project' } ) )
				// 性别
				$fn.setRow(formData, 'sex', await f.getDicCache({ code:45700 } ) )
				//
				this.setState({ formData })
			})
		})
	}
	
	render(){
		return SubmitForm.call(this, { labelWidth:'s7', api:'sp-additional-item/add' })
	}
}

export default Index